<!DOCTYPE html>
<html>
  <head><meta name="generator" content="Hexo 3.8.0">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="fengzhaoyang&#39;s blog">
  <meta name="keyword" content="hexo-theme, vuejs">
  
  <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
    CentOS shell 脚本 部署应用 | fzy-blog
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/css/style.css">
  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
  <script src="/js/qrious.js"></script>
  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


</head>
<div class="wechat-share">
  <img src="/css/images/logo.png">
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>fzy-blog</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">Home</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">Tags</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">Archives</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">Projects</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">About</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">Home</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">Tags</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">Archives</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">Projects</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">About</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>CentOS shell 脚本 部署应用</h2>
  <p class="post-date">2019-05-24</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="CentOS-shell-脚本-部署应用"><a href="#CentOS-shell-脚本-部署应用" class="headerlink" title="CentOS shell 脚本 部署应用"></a>CentOS shell 脚本 部署应用</h1><p>自动化部署脚本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">AppName=bop-server-eureka</span><br><span class="line">Now=`date "+%Y%m%d%H%M%S"`</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>判断进程是否存在，如果不存在就启动它如果存在就重启它</span><br><span class="line">PIDS=`ps -ef |grep $AppName |grep -v grep | awk '&#123;print $2&#125;'`</span><br><span class="line">if [ "$PIDS" != "" ]; then</span><br><span class="line">kill -9 $PIDS</span><br><span class="line">fi</span><br><span class="line"><span class="meta">#</span>先关闭进程，在运行此进程</span><br><span class="line"></span><br><span class="line">cp /var/lib/jenkins/workspace/bop-microservice-lab-test/bop-server-eureka/target/bop-server-eureka-1.0.0-SNAPSHOT.jar .</span><br><span class="line"></span><br><span class="line">java -jar bop-server-eureka-1.0.0-SNAPSHOT.jar &gt; log."$Now".log 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>
<p>tomcat 自动化部署脚本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>!/bin/sh</span><br><span class="line"><span class="meta">#</span>应用路径</span><br><span class="line">domain=/opt/uniskzhongchou</span><br><span class="line">project=ZCSystem</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>年月日时分秒</span><br><span class="line">DATE=$(date +%Y%m%d%H%M%S)</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>准备工作  通过rz -y 命令 把最新代码上传到$domain/tomcat目录下</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>1.停止tomcat服务</span><br><span class="line">cd $domain/tomcat/bin</span><br><span class="line"></span><br><span class="line">./shutdown.sh</span><br><span class="line"></span><br><span class="line">sleep 3</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>2.备份数据库表结构及表数据</span><br><span class="line"><span class="meta">#</span>mysqldump -uroot -pchaoxin zhongchou &gt; /opt/uniskzhongchou/backup/zhongzhou-$DATE.sql</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>3.备份上一版代码</span><br><span class="line">mv $domain/tomcat/webapps/$project.war $domain/backup/$project-$DATE.war</span><br><span class="line"></span><br><span class="line">rm -rf $domain/tomcat/logs/*</span><br><span class="line">rm -rf $domain/tomcat/webapps/$project/*</span><br><span class="line">rm -rf $domain/tomcat/webapps/ROOT/*</span><br><span class="line">rm -rf $domain/tomcat/work/Catalina/*</span><br><span class="line">rm -rf $domain/logs/*</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>4.复制最新上传的代码到tomcat/webapps/$project目录下</span><br><span class="line">cp $domain/tomcat/$project.war $domain/tomcat/webapps/$project/$project.war</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>5.解压war包</span><br><span class="line">cd $domain/tomcat/webapps/$project</span><br><span class="line"></span><br><span class="line">jar -xvf $project.war</span><br><span class="line"></span><br><span class="line">sleep 3</span><br><span class="line"></span><br><span class="line">mv $domain/tomcat/webapps/$project/$project.war $domain/tomcat/webapps/$project.war</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>6.启动tomcat服务</span><br><span class="line">cd $domain/tomcat/bin</span><br><span class="line"></span><br><span class="line">./startup.sh</span><br></pre></td></tr></table></figure>
<p>CentOS shell 脚本</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>!/bin/sh</span><br><span class="line"><span class="meta">#</span>应用路径</span><br><span class="line">domain=/opt/uniskzhongchou</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>年月日时分秒</span><br><span class="line">DATE=$(date +%Y%m%d%H%M%S)</span><br><span class="line"></span><br><span class="line">cd $domain/tomcat/bin</span><br><span class="line"></span><br><span class="line">./shutdown.sh</span><br><span class="line"></span><br><span class="line">sleep 3</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>1.备份数据库表结构及表数据</span><br><span class="line">mysqldump -uroot -pchaoxin zhongchou &gt; /opt/uniskzhongchou/backups/zhongzhou-$DATE.sql</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span>2.备份代码</span><br><span class="line">cp $domain/tomcat/webapps/ZCSystem.war $domain/backups/ZCSystem-$DATE.war</span><br><span class="line"></span><br><span class="line">rm -rf $domain/tomcat/logs/*</span><br><span class="line">rm -rf $domain/tomcat/webapps/ZCSystem*</span><br><span class="line">rm -rf $domain/tomcat/work/Catalina/*</span><br><span class="line">rm -rf $domain/logs/*</span><br></pre></td></tr></table></figure>
</section>
    <!-- Tags START -->
    
    <div class="tags">
      <span>Tags:</span>
      
  <a href="/tags#Linux">
    <span class="tag-code">Linux</span>
  </a>

    </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2019/05/24/Linux/CentOS配置ngnixconf/">
        <span class="nav-arrow">← </span>
        
          CentOS 配置 ngnix conf
        
      </a>
    
    
      <a class="nav-right" href="/2019/05/24/Linux/CentOSshell脚本备份远程服务器文件/">
        
          CentOS shell 脚本 备份远程服务器文件
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
    <div class="money-like">
      <div class="reward-btn">
        赏
        <span class="money-code">
          <span class="alipay-code">
            <div class="code-image"></div>
            <b>使用支付宝打赏</b>
          </span>
          <span class="wechat-code">
            <div class="code-image"></div>
            <b>使用微信打赏</b>
          </span>
        </span>
      </div>
      <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
    </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
    <div class="qrcode">
      <canvas id="share-qrcode"></canvas>
      <p class="notice">扫描二维码，分享此文章</p>
    </div>
    
    <!-- 二维码 END -->
    
    <!-- No Comment -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
  <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#CentOS-shell-脚本-部署应用"><span class="toc-nav-text">CentOS shell 脚本 部署应用</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'https://fengzhaoy.github.io/2019/05/24/Linux/CentOSshell脚本部署应用/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function () {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function () {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="' + src +
          '" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function () {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


<script>
  var qr = new QRious({
    element: document.getElementById('share-qrcode'),
    value: document.location.href
  });
</script>





    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2019
  </p>
</footer>

<script>
  function async (u, c) {
    var d = document,
      t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) {
      o.addEventListener('load', function (e) {
        c(null, e);
      }, false);
    }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async ("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function () {
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async ("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function () {
    $('figure pre').each(function (i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->

<script src="/js/script.js"></script>
  </body>
</html>